package com.cap.bts.crmdp.dealer.coupon.service.impl;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cap.bts.crmdp.dealer.coupon.constants.CouponConstants;
import com.cap.bts.crmdp.dealer.coupon.dao.IEligibilityDao;
import com.cap.bts.crmdp.dealer.coupon.dao.IEligibilityLineDao;
import com.cap.bts.crmdp.dealer.coupon.dao.ISqlDao;
import com.cap.bts.crmdp.dealer.coupon.dao.ITicKetDefineDao;
import com.cap.bts.crmdp.dealer.coupon.dao.ITicketLineDefineDao;
import com.cap.bts.crmdp.dealer.coupon.dao.ITicketLinePriceDao;
import com.cap.bts.crmdp.dealer.coupon.dao.ITicketPriceOfDealerDao;
import com.cap.bts.crmdp.dealer.coupon.domain.Eligibility;
import com.cap.bts.crmdp.dealer.coupon.domain.EligibilityLine;
import com.cap.bts.crmdp.dealer.coupon.domain.Sql;
import com.cap.bts.crmdp.dealer.coupon.domain.Ticket;
import com.cap.bts.crmdp.dealer.coupon.domain.TicketLine;
import com.cap.bts.crmdp.dealer.coupon.domain.TicketLinePriceModel;
import com.cap.bts.crmdp.dealer.coupon.domain.TicketPriceOfDealer;
import com.cap.bts.crmdp.dealer.coupon.dto.DealerInScopeDto;
import com.cap.bts.crmdp.dealer.coupon.dto.ProductTypesDto;
import com.cap.bts.crmdp.dealer.coupon.dto.TicKetDefineDto;
import com.cap.bts.crmdp.dealer.coupon.dto.TicketLinePriceDto;
import com.cap.bts.crmdp.dealer.coupon.dto.TicketPriceOfDealerDto;
import com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService;
import com.cap.bts.crmdp.dealer.masterdata.dao.IMaintainDealerDao;
import com.cap.bts.crmdp.dealer.masterinfo.dao.IOtherProductDao;
import com.cap.bts.crmdp.dealer.masterinfo.dao.IServiceInfoDefDao;
import com.cap.bts.crmdp.dealer.masterinfo.dao.ITyreProductDao;
import com.cap.bts.crmdp.dealer.masterinfo.domain.OtherProductModel;
import com.cap.bts.crmdp.dealer.masterinfo.domain.ServiceInfoDefModel;
import com.cap.bts.crmdp.dealer.masterinfo.domain.TyreProductModel;
import com.cap.bts.crmdp.dealer.masterinfo.dto.OtherProductDto;
import com.cap.bts.crmdp.dealer.masterinfo.dto.ServiceInfoDefDto;
import com.cap.bts.crmdp.dealer.masterinfo.dto.TyreProductDto;
import com.cap.bts.crmdp.dealer.meal.dao.IMealManageDao;
import com.cap.bts.crmdp.dealer.meal.domain.MealModel;
import com.cap.bts.crmdp.dealer.meal.domain.MeallineModel;
import com.cap.bts.crmdp.dealer.meal.service.IMealManageService;
import com.cap.bts.crmdp.dealer.purchase.dao.IPackageDefinitionDao;
import com.cap.bts.framework.codemapping.dao.ICodeMappingDao;
import com.cap.bts.framework.codemapping.domain.CodeInfo;
import com.cap.bts.framework.common.exception.AppException;

@Transactional(rollbackFor = AppException.class)
@Service
public class TicKetDefineServiceImpl implements ITicKetDefineService {

    @Autowired
    ITicKetDefineDao            iTicKetDefineDao;

    @Autowired
    ITicketLineDefineDao        iTicketLineDefineDao;

    @Autowired
    IMealManageService          mealManageService;

    @Autowired
    ITicketLinePriceDao         iTicketLinePriceDao;
    @Autowired
    ICodeMappingDao             codeMappingDao;
    @Autowired
    IEligibilityDao             eligibilityDao;
    @Autowired
    IEligibilityLineDao         eligibilityLineDao;
    @Autowired
    IServiceInfoDefDao          serviceInfoDefDao;
    @Autowired
    ITyreProductDao             tyreProductDao;
    @Autowired
    IOtherProductDao            otherProductDao;
    @Autowired
    ISqlDao                     sqlDao;
    @Autowired
    IMaintainDealerDao          dealerDao;
    @Autowired
    ITicketPriceOfDealerDao     ticketPriceOfDealerDao;

    @Autowired
    IMealManageDao              iMealManageDao;
    
    @Autowired
    IPackageDefinitionDao packageDefinitionDao;

    private static final Logger LOGGER = Logger.getLogger(TicKetDefineServiceImpl.class);

    /**
     * 新增提货券和优惠券信息
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#insertRedemptionInfo(com.cap.bts.crmdp.dealer.coupon.dto.TicKetDefineDto)
     */
    @Override
    public Ticket insertTicketInfo(TicKetDefineDto ticKetDefineDto) throws AppException {
        Ticket ticket = new Ticket();
        ticket.setTicketName(ticKetDefineDto.getTicketName());//名称
        ticket.setTicketType(ticKetDefineDto.getTicketType());//类型
        ticket.setVerificationMethod(ticKetDefineDto.getVerificationMethod());//抵扣凭证
        ticket.setDeductionMethod(ticKetDefineDto.getDeductionMethod());//抵扣方式
        ticket.setDeductionAmount(ticKetDefineDto.getDeductionAmount());//抵扣值
        //提货券
        if (CouponConstants.TICKET_TYPE_REDEMPTION.equals(ticKetDefineDto.getTicketType())) {
            ticket.setIfPrepay(ticKetDefineDto.getIfPrepay());//是否预付费
        } else if (CouponConstants.TICKET_TYPE_COUPON.equals(ticKetDefineDto.getTicketType())) {//优惠券
            ticket.setSmsRemind(ticKetDefineDto.getSmsRemind());//是否发送信息
        }

        return iTicKetDefineDao.insertTicketInfo(ticket);
    }

    /**
     * 新增优惠券和提货券的行信息
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#insertCouponInfo(com.cap.bts.crmdp.dealer.coupon.dto.TicKetDefineDto)
     */
    @Override
    public TicketLine insertTicketLineInfo(TicKetDefineDto ticKetDefineDto) throws AppException {
        TicketLine ticketLine = new TicketLine();
        ticketLine.setItemName(ticKetDefineDto.getItemName());
        ticketLine.setPrepayAmount(ticKetDefineDto.getPrepayAmount());
        ticketLine.setQuantity(ticKetDefineDto.getQuantity());

        ticketLine.setTicketDefId(ticKetDefineDto.getTicketDefId());

        return iTicketLineDefineDao.insertTicketLineInfo(ticketLine);
    }

    /**
     * 提货券和优惠券信息查询
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getTicketList(com.cap.bts.crmdp.dealer.coupon.dto.TicKetDefineDto)
     */
    @Override
    public List<Ticket> getTicketList(TicKetDefineDto ticKetDefineDto) throws AppException {
        return iTicKetDefineDao.getTicketList(ticKetDefineDto);
    }

    /**
     * 取得优惠券定义列表 
     * overridden:
     * @Date        :      Sep 10, 2015
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getCouponTicketList()
    **/
    @Override
    public List<Ticket> getCouponTicketList() throws AppException {
        return iTicKetDefineDao.getCouponTicketList();
    }

    /**
     * 根据优惠券名称查询信息
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getTicketByTicketName(com.cap.bts.crmdp.dealer.coupon.dto.TicKetDefineDto)
     */
    @Override
    public boolean getTicketByTicketName(TicKetDefineDto ticKetDefineDto) throws AppException {
        if (iTicKetDefineDao.getTicketByTicketName(ticKetDefineDto)) {
            return true;
        }
        return false;
    }

    /**
     * 根据优惠券和提货券ID查询信息
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getTicketById(com.cap.bts.crmdp.dealer.coupon.dto.TicKetDefineDto)
     */
    @Override
    public Ticket getTicketById(String id) throws AppException {
        return iTicKetDefineDao.getTicketById(id);
    }

    /**
     * 查询所有的优惠券和提货券信息
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getAllTicketList()
     */
    @Override
    public List<Ticket> getAllTicketList() throws AppException {
        return iTicKetDefineDao.getAllTicketList();
    }

    /**
     * 根据优惠券和提货券ID查询其详细信息
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getTicketLineInfoList(java.lang.String)
     */
    @Override
    public List<TicketLine> getTicketLineInfoList(String ticketId) throws AppException {
        return iTicketLineDefineDao.getTicketLineInfoList(ticketId);
    }

    /**
     * 根据优惠券和提货券的详细信息的ID查询其详细信息
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getTicketLineInfo(java.lang.Long)
     */
    @Override
    public TicketLine getTicketLineInfoById(Long id) throws AppException {
        return iTicketLineDefineDao.getTicketLineInfoById(id);

    }

    /**
     * 修改优惠券和提货券信息
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#updateCouponInfo(com.cap.bts.crmdp.dealer.coupon.dto.TicKetDefineDto)
     */
    @Override
    public boolean updateTicketInfo(TicKetDefineDto ticKetDefineDto) throws AppException {
        if (iTicKetDefineDao.updateTicketInfo(ticKetDefineDto)) {
            return true;
        }
        return false;
    }

    /**
     * 根据ID删除优惠券和提货券的详细信息
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#removeTiketLineInfo(com.cap.bts.crmdp.dealer.coupon.dto.TicKetDefineDto)
     */
    @Override
    public boolean removeTiketLineInfo(TicKetDefineDto ticKetDefineDto) throws AppException {
        iTicketLineDefineDao.remove(ticKetDefineDto.getId());
        removeMealPriceByTicketId(ticKetDefineDto.getId());
        return true;
    }

    /**
     * 优惠券和提货券的详细信息修改
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#updateTiketLineInfo(com.cap.bts.crmdp.dealer.coupon.dto.TicKetDefineDto)
     */
    @Override
    public boolean updateTiketLineInfo(TicKetDefineDto ticKetDefineDto) throws AppException {
        if (iTicketLineDefineDao.updateTiketLineInfo(ticKetDefineDto)) {
            return true;
        }
        return false;
    }

    /**
     * 根据ID删除优惠券和提货券的信息
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#removeTicketInfo(java.lang.Long)
     */
    @SuppressWarnings("rawtypes")
    @Override
    public boolean removeTicketInfo(Long id) throws AppException {
        iTicKetDefineDao.remove(id);
        List<TicketLine> ticketLineList = getTicketLineInfoList(id.toString());
        if (!ticketLineList.isEmpty()) {
            for (Iterator iterator = ticketLineList.iterator(); iterator.hasNext();) {
                TicketLine ticketLine = (TicketLine) iterator.next();
                removeMealPriceByTicketId(ticketLine.getId());
            }
        }
        removeTicketLineInfoByTicketDefId(id);
        return true;
    }

    /**
     * 根据ticketDefId删除优惠券和提货券的详细信息
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#removeTicketLineInfoByTicketDefId(java.lang.Long)
     */
    @Override
    public boolean removeTicketLineInfoByTicketDefId(Long ticketDefId) throws AppException {
        List<TicketLine> ticketLineList = getTicketLineInfoList(Long.toString(ticketDefId));
        if (!ticketLineList.isEmpty()) {
            if (iTicketLineDefineDao.removeTicketLineInfoByTicketDefId(ticketLineList)) {
                return true;
            }
        } else {
            return true;
        }
        return false;
    }

    /**
     * 根据优惠券名称查询信息
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getTicketByTicketName2(com.cap.bts.crmdp.dealer.coupon.dto.TicKetDefineDto)
     */
    @Override
    public Ticket getTicketByTicketName2(TicKetDefineDto ticKetDefineDto) throws AppException {
        return iTicKetDefineDao.getTicketByTicketName2(ticKetDefineDto);
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年10月20日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getProductTypes()
    **/
    @Override
    public List<ProductTypesDto> getProductTypes() throws AppException {
        List<CodeInfo> list = codeMappingDao.getProductTypes();
        List<ProductTypesDto> productTypeList = new ArrayList<ProductTypesDto>();
        if (list != null && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                ProductTypesDto productType = new ProductTypesDto();
                productType.setProductType(list.get(i).getCode());
                productType.setParentCode(list.get(i).getParentCode());
                productType.setCodeValue(list.get(i).getValue());
                productTypeList.add(productType);
            }
        }
        return productTypeList;
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年10月20日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getPropertyOfProduct(java.lang.String)
    **/
    @Override
    public String getDescriptionOfProduct(String value) throws AppException {
        List<Object> propertyOfProductList = codeMappingDao.getPropertyOfProduct(value);
        String description = null;
        if (propertyOfProductList != null && !propertyOfProductList.isEmpty()) {
            description = propertyOfProductList.get(0).toString();
        }
        return description;
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年10月23日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getEligibilityByTicketLineId(java.lang.Long)
    **/
    @Override
    public List<Eligibility> getEligibilityByTicketLineId(Long id) throws AppException {
        return eligibilityDao.getEligibilityByTicketLineId(id);
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年10月25日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#isExitsRow(java.lang.Long, java.lang.Long)
    **/
    @Override
    public boolean isExitsRow(Long id) throws AppException {
        List<EligibilityLine> rowList = eligibilityLineDao.getEligibilityLineById(id);
        if (rowList != null && !rowList.isEmpty()) {
            return true;
        }
        return false;
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年10月25日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#saveRow(java.lang.Long, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
    **/
    @Override
    public boolean saveRow(Long eligibilityId,String attrName, String operator,String attrValue) throws AppException {
        try {
            EligibilityLine eligibilityLine = new EligibilityLine();
            eligibilityLine.setEligibilityId(eligibilityId);
            eligibilityLine.setAttrName(attrName);
            eligibilityLine.setOperator(operator);
            eligibilityLine.setAttrValue(attrValue);
            eligibilityLineDao.save(eligibilityLine);
            return true;
        } catch (Exception e) {
            LOGGER.error("saveRowErroe", e);
        }
        return false;
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年10月25日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#changeRow(java.lang.Long, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
    **/
    @Override
    public void changeRow(Long eligibilityId,String attrName, String operator,
                    String attrValue, String eligibilityLineId) throws AppException {
        try {
            EligibilityLine eligibilityLine = new EligibilityLine();
            eligibilityLine.setEligibilityId(eligibilityId);
            eligibilityLine.setAttrName(attrName);
            eligibilityLine.setOperator(operator);
            eligibilityLine.setAttrValue(attrValue);
            eligibilityLine.setId(Long.parseLong(eligibilityLineId));
            eligibilityLineDao.update(eligibilityLine);
        } catch (Exception e) {
            LOGGER.error("changeRowError", e);
        }
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年10月26日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#removeRow(java.lang.String)
    **/
    @Override
    public void removeRow(Long eligibilityLineId) throws AppException {
        try {
            eligibilityLineDao.remove(eligibilityLineId);
        } catch (Exception e) {
            LOGGER.error("removeRowError", e);
        }
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年10月26日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#isExitsInTable(java.lang.String)
    **/
    @Override
    public boolean isExitsInTable(String code) throws AppException {
        return false;
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年10月26日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getCodeListFromTable(java.lang.String)
    **/
    @Override
    public List<String> getCodeListFromTable(String tableName) throws AppException {
        return eligibilityDao.getCodeListFromTable(tableName);
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年10月27日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getCodeByValueAndType(java.lang.String, java.lang.String)
    **/
    @Override
    public String getCodeByValueAndType(String value, String type) throws AppException {
        List<String> codeList = eligibilityDao.getCodeByValueAndType(value, type);
        String code = null;
        if (codeList != null && !codeList.isEmpty()) {
            code = codeList.get(0);
        }
        return code;
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年10月27日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#showViewSQL(java.lang.String[], java.lang.String[], java.lang.String[], java.lang.StringBuilder, java.lang.StringBuilder, java.lang.StringBuilder, java.lang.StringBuilder)
    **/
    @Override
    public StringBuilder showViewSQL(String[] attrNameList,String[] operatorList,String[] attrValueList,StringBuilder where)
        throws AppException {
        for(int i = 0; i < attrNameList.length; i++){
            String code = attrNameList[i];
            if(code == null || code.isEmpty()){
                continue;
            }
            String[] valueList = attrValueList[i].split("\\|");
            if(valueList != null && valueList.length > 0 && operatorList!= null){
                if("equal".equals(operatorList[i])){
                    String pro = attrValueList[i].replace("|", "','");
                    StringBuilder equal = new StringBuilder();
                    equal.append(" " + code + " in('" + pro + "')");
                    where.append(equal);
                }else if("notEqual".equals(operatorList[i])){
                    String pro = attrValueList[i].replace("|", "','");
                    StringBuilder equal = new StringBuilder();
                    equal.append(" " + code + " not in('" + pro + "')");
                    where.append(equal);
                }else if("include".equals(operatorList[i])){
                    StringBuilder equal = new StringBuilder();
                    for (int k = 0; k < valueList.length; k++) {
                        equal
                            .append(code + " like '%" + valueList[k] + "%'");
                        if (k != valueList.length - 1) {
                            equal.append(" or ");
                        }
                    }
                    where.append(" (" + equal + ")");
                }else if("notInclude".equals(operatorList[i])){
                    StringBuilder equal = new StringBuilder();
                    for (int k = 0; k < valueList.length; k++) {
                        equal.append(code + " not like '%" + valueList[k]
                                     + "%'");
                        if (k != valueList.length - 1) {
                            equal.append(" or ");
                        }
                    }
                    where.append(" (" + equal + ")");
                }
                if (i != attrNameList.length - 1 && attrNameList[i+1] != null) {
                    where.append(" and ");
                } else {
                    where.append(";");
                }
            }
        }
        return where;
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年10月27日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getViewForService(java.lang.String)
    **/
    @Override
    public List<ServiceInfoDefDto> getViewForService(String sql) throws AppException {
        List<ServiceInfoDefModel> serviceInfoDefList = serviceInfoDefDao.getViewForService(sql);
        List<ServiceInfoDefDto> serviceInfoDefDtoList = new ArrayList<ServiceInfoDefDto>();
        if (serviceInfoDefList != null && !serviceInfoDefList.isEmpty()) {
            for (int i = 0; i < serviceInfoDefList.size(); i++) {
                ServiceInfoDefDto serviceInfoDefDto = new ServiceInfoDefDto();
                serviceInfoDefDto.setCode(serviceInfoDefList.get(i).getCode());
                serviceInfoDefDto.setName(serviceInfoDefList.get(i).getName());
                serviceInfoDefDtoList.add(serviceInfoDefDto);
            }
        }
        return serviceInfoDefDtoList;
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年10月27日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getViewForTyre(java.lang.String)
    **/
    @Override
    public List<TyreProductDto> getViewForTyre(String sql) throws AppException {
        List<TyreProductModel> tyreProductModelList = tyreProductDao.getViewForTyre(sql);
        List<TyreProductDto> tyreProductDtoList = new ArrayList<TyreProductDto>();
        if (tyreProductModelList != null && !tyreProductModelList.isEmpty()) {
            for (int i = 0; i < tyreProductModelList.size(); i++) {
                TyreProductDto tyreProductDto = new TyreProductDto();
                tyreProductDto.setMfgrCode(tyreProductModelList.get(i).getMfgrCode());
                tyreProductDto.setDescription1(tyreProductModelList.get(i).getDescription1());
                tyreProductDto.setDescription2(tyreProductModelList.get(i).getDescription2());
                tyreProductDtoList.add(tyreProductDto);
            }
        }
        return tyreProductDtoList;
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年10月27日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getViewForOtherProduct(java.lang.String)
    **/
    @Override
    public List<OtherProductDto> getViewForOtherProduct(String sql) throws AppException {
        List<OtherProductModel> otherProductModelList = otherProductDao.getViewForOtherProduct(sql);
        List<OtherProductDto> otherProductDtoList = new ArrayList<OtherProductDto>();
        if (otherProductModelList != null && !otherProductModelList.isEmpty()) {
            for (int i = 0; i < otherProductModelList.size(); i++) {
                OtherProductDto otherProductDto = new OtherProductDto();
                otherProductDto.setMfgrCode(otherProductModelList.get(i).getMfgrCode());
                otherProductDto.setDescription1(otherProductModelList.get(i).getBrandNameCN());
                otherProductDto.setDescription2(otherProductModelList.get(i).getNameCn());
                otherProductDtoList.add(otherProductDto);
            }
        }
        return otherProductDtoList;
    }

    /**
     * 根据优惠券行ID查询价目表信息
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getMealPriceListByPackageId(com.cap.bts.crmdp.dealer.coupon.dto.TicketLinePriceDto)
     */
    @Override
    public List<TicketLinePriceModel> getMealPriceListByPackageId(TicketLinePriceDto ticketLinePriceDto)
                                                                                                        throws AppException {
        return iTicketLinePriceDao.getMealPriceListByPackageId(ticketLinePriceDto);
    }

    /**
     * 价目表信息新新增
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#saveMealPriceinfo(com.cap.bts.crmdp.dealer.coupon.dto.TicketLinePriceDto)
     */
    @Override
    public boolean saveMealPriceinfo(TicketLinePriceDto dto) throws AppException {
        String priceStr = dto.getPriceStr();
        TicketLinePriceModel ticketLinePriceModel = null;
        if (priceStr != null && !"".equals(priceStr)) {
            String[] data = priceStr.split("###");
            for (int i = 0; i < data.length; i++) {
                String[] pStrings = data[i].split("@#");
                String code = pStrings[0];
                String value = pStrings[1];
                String price = pStrings[2];
                ticketLinePriceModel = new TicketLinePriceModel();
                ticketLinePriceModel.setCode(code);
                ticketLinePriceModel.setCodeType(dto.getCodeType());
                ticketLinePriceModel.setTicketLineId(dto.getTicketLineId());
                ticketLinePriceModel.setValue(value);
                ticketLinePriceModel.setPrice(Double.parseDouble(price));
                iTicketLinePriceDao.save(ticketLinePriceModel);
            }
        }
        return true;
    }

    /**
     * 根据价目表ID删除价目表信息
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#removeMealPriceById(java.lang.Long)
     */
    @Override
    public boolean removeMealPriceById(Long id) throws AppException {
        iTicketLinePriceDao.remove(id);
        return true;
    }

    /**
     * 根据参数查询价目表信息
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getMealPriceInfo(com.cap.bts.crmdp.dealer.coupon.dto.TicketLinePriceDto)
     */
    @Override
    public TicketLinePriceModel getMealPriceInfo(TicketLinePriceDto dto) throws AppException {
        return iTicketLinePriceDao.getMealPriceInfo(dto);
    }

    /**
     * 修改价目表信息
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#updateMealPriceInfo(com.cap.bts.crmdp.dealer.coupon.dto.TicketLinePriceDto)
     */
    @Override
    public boolean updateMealPriceInfo(TicketLinePriceDto dto) throws AppException {
        TicketLinePriceModel ticketLinePriceModel = new TicketLinePriceModel();
        ticketLinePriceModel.setId(dto.getId());
        ticketLinePriceModel.setTicketLineId(dto.getTicketLineId());
        ticketLinePriceModel.setCodeType(dto.getCodeType());
        ticketLinePriceModel.setCode(dto.getCode());
        ticketLinePriceModel.setValue(dto.getValue());
        ticketLinePriceModel.setPrice(dto.getPrice());

        iTicketLinePriceDao.update(ticketLinePriceModel);
        return true;
    }

    /**
     * 根据提货券行ID查询价目表信息
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getMealPriceByTicketId(com.cap.bts.crmdp.dealer.coupon.dto.TicketLinePriceDto)
     */
    @Override
    public List<TicketLinePriceModel> getMealPriceByTicketId(TicketLinePriceDto dto)
                                                                                    throws AppException {
        return iTicketLinePriceDao.getMealPriceByPackageId(dto);
    }

    /**
     * 根据提货券行ID删除价目表信息
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#removeMealPriceByTicketId(java.lang.Long)
     */
    @SuppressWarnings("rawtypes")
    @Override
    public void removeMealPriceByTicketId(Long ticketLineId) throws AppException {
        TicketLinePriceDto ticketLinePriceDto = new TicketLinePriceDto();
        ticketLinePriceDto.setTicketLineId(ticketLineId);
        List<TicketLinePriceModel> ticketLinePriceList = getMealPriceByTicketId(ticketLinePriceDto);
        for (Iterator iterator = ticketLinePriceList.iterator(); iterator.hasNext();) {
            TicketLinePriceModel ticketLinePriceModel = (TicketLinePriceModel) iterator.next();
            iTicketLinePriceDao.remove(ticketLinePriceModel);
        }
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年10月28日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#saveSql(java.lang.String)
    **/
    @Override
    public void saveSql(String sql) throws AppException {
        if (sql != null) {
            Sql sqlToSave = new Sql();
            sqlToSave.setSql(sql);
            sqlDao.save(sqlToSave);
        }
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年10月28日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#querySql(java.lang.String)
    **/
    @Override
    public Long querySql(String sql) throws AppException {
        List<Sql> sqlList = sqlDao.querySql(sql);
        Long id = null;
        if (sqlList != null && !sqlList.isEmpty()) {
            id = sqlList.get(0).getId();
        }
        return id;
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年10月28日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#querySqlById(java.lang.Long)
    **/
    @Override
    public String querySqlById(Long id) throws AppException {
        List<Sql> sqlList = sqlDao.querySqlById(id);
        String querySql = null;
        if (sqlList != null && !sqlList.isEmpty()) {
            querySql = sqlList.get(0).getSql();
        }
        return querySql;
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年10月29日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#deleteSqlById(java.lang.Long)
    **/
    @Override
    public void deleteSqlById(Long id) throws AppException {
        if (id != null) {
            sqlDao.remove(id);
        }

    }

    /**
     * 根据优惠券和提货券的ID查询有效状态的套餐是否存在
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getMealModelListByTicketId(com.cap.bts.crmdp.dealer.coupon.dto.TicKetDefineDto)
     */
    @Override
    public boolean getMealModelListByTicketId(TicKetDefineDto ticKetDefineDto) throws AppException {
        List<MealModel> list = iMealManageDao.getMealModelListByTicketId(ticKetDefineDto
            .getTicketDefId());
        if (!list.isEmpty() && !list.isEmpty()) {
            return true;
        }
        return false;
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月3日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#saveTicketPriceOfDealer(com.cap.bts.crmdp.dealer.coupon.dto.TicketLinePriceDto)
    **/
    @SuppressWarnings("rawtypes")
    @Override
    public boolean saveTicketPriceOfDealer() throws AppException {
        try {
            List<TicketLinePriceModel> ticketLineList = iTicketLinePriceDao.getAllTicketLine();
            if(ticketLineList != null && !ticketLineList.isEmpty()){
                List<DealerInScopeDto> dealerInScopeList = new ArrayList<DealerInScopeDto>();
                //删除所有套餐，套餐行
                ticketPriceOfDealerDao.deletePackageAndTicketLine();
                //ticket_line_price中存在,在package_price不存在的ticket_line_price中的记录
                List<BigInteger> ticketPriceOfDealerNotInPackageList = ticketPriceOfDealerDao.checkTicketLinePriceNotInPackagePriceByTicketLineId();
                if(ticketPriceOfDealerNotInPackageList != null && !ticketPriceOfDealerNotInPackageList.isEmpty()){
                    for(int i=0; i<ticketPriceOfDealerNotInPackageList.size(); i++){
                        ticketPriceOfDealerDao.deleteTicketLinePriceByTicketLineId(ticketPriceOfDealerNotInPackageList.get(i).longValue());
                    }
                }
                for(int i=0; i< ticketLineList.size(); i++){
                    //根据ticket-id删除存在于tm_raw_ticket_line_price中的记录
                    List<TicketPriceOfDealer> ticketPriceOfDealerList = ticketPriceOfDealerDao.checkTicketLinePriceByTicketLineId(ticketLineList.get(i).getTicketLineId());
                    if(ticketPriceOfDealerList != null && !ticketPriceOfDealerList.isEmpty()){
                        ticketPriceOfDealerDao.deleteTicketLinePriceByTicketLineId(ticketLineList.get(i).getTicketLineId());
                    }
                    
                    if(CouponConstants.PROVINCE.equals(ticketLineList.get(i).getCode().substring(2))){
                        //省
                        DealerInScopeDto dealerInScope = saveTicketPriceMethod(ticketLineList.get(i), CouponConstants.PROVINCE);
                        if(dealerInScope != null){
                            dealerInScopeList.add(dealerInScope);
                        }
                    }else if(CouponConstants.CITY.equals(ticketLineList.get(i).getCode().substring(2))){
                        //市
                        DealerInScopeDto dealerInScope = saveTicketPriceMethod(ticketLineList.get(i), CouponConstants.CITY);
                        if(dealerInScope != null){
                            dealerInScopeList.add(dealerInScope);
                        }
                    }else if(CouponConstants.COUNTY.equals(ticketLineList.get(i).getCode().substring(2))){
                        //县
                        DealerInScopeDto dealerInScope = saveTicketPriceMethod(ticketLineList.get(i), CouponConstants.COUNTY);
                        if(dealerInScope != null){
                            dealerInScopeList.add(dealerInScope);
                        }
                    }else if(CouponConstants.REGION_CODE.equals(ticketLineList.get(i).getCode().substring(2))){
                        //区域代码
                        DealerInScopeDto dealerInScope = saveTicketPriceMethod(ticketLineList.get(i), CouponConstants.REGION_CODE);
                        if(dealerInScope != null){
                            dealerInScopeList.add(dealerInScope);
                        }
                    }else if(CouponConstants.DEALER.equals(ticketLineList.get(i).getCode().substring(2))){
                        //门店
                        DealerInScopeDto dealerInScope = saveTicketPriceMethod(ticketLineList.get(i), CouponConstants.DEALER_NUM);
                        if(dealerInScope != null){
                            dealerInScopeList.add(dealerInScope);
                        }
                    }
                }
                //处理优先级的问题，保留优先级高的dealer记录
                if(dealerInScopeList != null && !dealerInScopeList.isEmpty()){
                    //构造优先级的map
                    Map<String,Integer> priority = new HashMap<String,Integer>();
                    List<CodeInfo> priorityList = codeMappingDao.getCodeInfoByCodeType(CouponConstants.DEALERPROPERTY);
                    if(priorityList != null && !priorityList.isEmpty()){
                        for(int i=0; i<priorityList.size(); i++){
                            priority.put(priorityList.get(i).getCode().substring(2), Integer.parseInt(priorityList.get(i).getCode().substring(0, 1)));
                        }
                    }
                    //判断是否存在优先级问题
                    for(int i=0; i<dealerInScopeList.size(); i++){
                        for(int j=0; j<dealerInScopeList.size(); j++){
                           String code1 = dealerInScopeList.get(i).getCode();
                           String code2 = dealerInScopeList.get(j).getCode();
                           if(code1 != null  && code2 != null){
                               //同级不比较
                               if(code1.equals(code2)){
                                   continue;
                               }
                               //不同级，删除低等级List中存在于高等级list中的元素
                               if(!(code1.equals(code2))){
                                   Integer level1 = priority.get(code1);
                                   Integer level2 = priority.get(code2);
                                   if(level1 < level2){
                                       List<TicketPriceOfDealerDto> list2 = dealerInScopeList.get(j).getDealerInScopeList();
                                       List<TicketPriceOfDealerDto> list1 = dealerInScopeList.get(i).getDealerInScopeList();
                                       if(list2 != null && !list2.isEmpty() && list1 != null && !list1.isEmpty()){
                                           for(int k=0; k<list2.size(); k++){
                                               for(int l=0; l<list1.size(); l++){
                                                   if(list2.get(k).getDealerId().longValue() == list1.get(l).getDealerId().longValue()
                                                       && list2.get(k).getTicketLineId().longValue() == list1.get(l).getTicketLineId().longValue()){
                                                       list2.remove(k);
                                                       k--;
                                                       break;
                                                   }
                                               }
                                           }
                                       }
                                   }else if(level1 > level2){
                                       List<TicketPriceOfDealerDto> list2 = dealerInScopeList.get(j).getDealerInScopeList();
                                       List<TicketPriceOfDealerDto> list1 = dealerInScopeList.get(i).getDealerInScopeList();
                                       if(list2 != null && !list2.isEmpty() && list1 != null && !list1.isEmpty()){
                                           for(int k=0; k<list1.size(); k++){
                                               for(int l=0; l<list2.size(); l++){
                                                   if(list1.get(k).getDealerId().longValue() == list2.get(l).getDealerId().longValue()
                                                       && list1.get(k).getTicketLineId().longValue() == list2.get(l).getTicketLineId().longValue()){
                                                       list1.remove(k);
                                                       k--;
                                                       break;
                                                   }
                                               }
                                           }
                                       }
                                   }
                               }
                           }
                        }
                        //将dealerInScopeList中的剩余数据存入对应表中
                        List<TicketPriceOfDealerDto> list = dealerInScopeList.get(i).getDealerInScopeList();
                        if(list != null && !list.isEmpty()){
                            for(int m=0; m<list.size();m++){
                                TicketPriceOfDealer  ticketPriceOfDealer = new TicketPriceOfDealer();
                                TicketLine ticketLine = iTicketLineDefineDao.getTicketLineInfoById(list.get(m).getTicketLineId());
                                if(ticketLine != null){
                                	double price = list.get(m).getPrice() - ticketLine.getPrepayAmount()/ticketLine.getQuantity();
                                	ticketPriceOfDealer.setTicketLineId(list.get(m).getTicketLineId());
                                	ticketPriceOfDealer.setDealerId(list.get(m).getDealerId());
                                	ticketPriceOfDealer.setObjectType(CouponConstants.TICKET_LINE);
                                	ticketPriceOfDealer.setPrice(price);
                                	ticketPriceOfDealerDao.save(ticketPriceOfDealer);
                                }
                            }
                        }
                    }
                }
            }
            
            //添加具体门店的ticket的价格
            List<Object[]> ticketAndDealerList = ticketPriceOfDealerDao.getTicketDefIdAndDealerId();
            if(ticketAndDealerList != null && !ticketAndDealerList.isEmpty()){
                for(int i=0; i<ticketAndDealerList.size(); i++){
                    Object[] obj = ticketAndDealerList.get(i);
                    Long ticketId = Long.parseLong(obj[0].toString());
                    Long dealerId = Long.parseLong(obj[1].toString());
                    List<TicketLine> ticketlineList = iTicketLineDefineDao.getTicketLineInfoList(Long.toString(ticketId));
                    if (ticketlineList != null && !ticketlineList.isEmpty()) {
                        Double prepayAmount = 0.00;
                        for (Iterator iterator2 = ticketlineList.iterator(); iterator2.hasNext();) {
                            TicketLine ticketLine = (TicketLine) iterator2.next();
                            List<TicketPriceOfDealer> ticketPriceOfDealerList = 
                                ticketPriceOfDealerDao.getTicketLinePriceByTicketLineIdAndDealerId(ticketLine.getId(), 
                                    dealerId);
                            if(ticketPriceOfDealerList != null && !ticketPriceOfDealerList.isEmpty()){
                                TicketPriceOfDealer ticketPriceOfDealer = ticketPriceOfDealerList.get(0);
                                prepayAmount = prepayAmount + ticketLine.getPrepayAmount()
                                    + (ticketPriceOfDealer.getPrice() * ticketLine.getQuantity());
                            }else{
                                prepayAmount = prepayAmount + ticketLine.getPrepayAmount();
                            }
                        }
                        TicketPriceOfDealer  ticketPriceOfDealer = new TicketPriceOfDealer();
                        ticketPriceOfDealer.setDealerId(dealerId);
                        ticketPriceOfDealer.setObjectId(ticketId);
                        ticketPriceOfDealer.setObjectType(CouponConstants.TICKET);
                        ticketPriceOfDealer.setPrice(prepayAmount);
                        ticketPriceOfDealerDao.save(ticketPriceOfDealer);
                    }
                }
            }
            //添加具体门店的套餐的价格
            List<Object[]> packageAndDealerList = ticketPriceOfDealerDao.getPackageDefIdAndDealerId();
            if(packageAndDealerList != null && !packageAndDealerList.isEmpty()){
                for(int i=0; i<packageAndDealerList.size(); i++){
                    Object[] obj = packageAndDealerList.get(i);
                    Long packageId = Long.parseLong(obj[0].toString());
                    Long dealerId = Long.parseLong(obj[1].toString());
                    List<MeallineModel> meallineList = mealManageService.getMealLIneInfoByPackageId(packageId);
                    Double sumAmount = 0.00;
                    for(int j=0; j<meallineList.size(); j++){
                        MeallineModel mealline = meallineList.get(j);
                        Long ticketId = mealline.getTicketDefId();
                        //所有ticketLine
                        List<TicketLine> ticketlineList = iTicketLineDefineDao.getTicketLineInfoList(Long.toString(ticketId));
                        if (ticketlineList != null && !ticketlineList.isEmpty()) {
                            Double prepayAmount = 0.00;
                            for (Iterator iterator2 = ticketlineList.iterator(); iterator2.hasNext();) {
                                TicketLine ticketLine = (TicketLine) iterator2.next();
                                List<TicketPriceOfDealer> ticketPriceOfDealerList = 
                                    ticketPriceOfDealerDao.getTicketLinePriceByTicketLineIdAndDealerId(ticketLine.getId(), 
                                        dealerId);
                                if(ticketPriceOfDealerList != null && !ticketPriceOfDealerList.isEmpty()){
                                    TicketPriceOfDealer ticketPriceOfDealer = ticketPriceOfDealerList.get(0);
                                    prepayAmount = prepayAmount + ticketLine.getPrepayAmount()
                                        + (ticketPriceOfDealer.getPrice() * ticketLine.getQuantity());
                                }else{
                                    prepayAmount = prepayAmount + ticketLine.getPrepayAmount();
                                }
                            }
                            double amount = prepayAmount * mealline.getNumberOfUse();
                            BigDecimal bigAmount = new BigDecimal(amount);
                            //四舍五入，如: 2.35变成2.4
                            amount = bigAmount.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                            sumAmount = sumAmount + amount;
                        }
                    }
                    //存入对应门店套餐的价格
                    TicketPriceOfDealer  ticketPriceOfDealer = new TicketPriceOfDealer();
                    ticketPriceOfDealer.setDealerId(dealerId);
                    ticketPriceOfDealer.setObjectId(packageId);
                    ticketPriceOfDealer.setObjectType(CouponConstants.PACKAGE);
                    ticketPriceOfDealer.setPrice(sumAmount);
                    ticketPriceOfDealerDao.save(ticketPriceOfDealer);
                }
            }
            return true;
        } catch (AppException e) {
            LOGGER.error("saveTicketPriceOfDealerError", e);
        }
        return false;
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月3日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#saveTicketPriceMethod(java.lang.String, java.lang.String)
    **/
    @Override
    public DealerInScopeDto saveTicketPriceMethod(TicketLinePriceModel ticketLine,String code) throws AppException {
        if(ticketLine != null && code != null){
            List<BigInteger> dealerIdList = dealerDao.getDealersByCode(code, ticketLine.getValue());
            List<TicketPriceOfDealerDto> ticketPriceOfDealerDtoList = new ArrayList<TicketPriceOfDealerDto>();
            if(dealerIdList != null && !dealerIdList.isEmpty()){
                DealerInScopeDto dealerInScope = new DealerInScopeDto();
                for(int z=0; z< dealerIdList.size(); z++){
                    TicketPriceOfDealerDto ticketPriceOfDealerDto = new TicketPriceOfDealerDto();
                    ticketPriceOfDealerDto.setTicketLineId(ticketLine.getTicketLineId());
                    ticketPriceOfDealerDto.setDealerId(dealerIdList.get(z).longValue());
                    ticketPriceOfDealerDto.setPrice(ticketLine.getPrice());
                    ticketPriceOfDealerDtoList.add(ticketPriceOfDealerDto);
                }
                dealerInScope.setDealerInScopeList(ticketPriceOfDealerDtoList);
                if(CouponConstants.DEALER_NUM.equals(code)){
                    dealerInScope.setCode(CouponConstants.DEALER);
                }else{
                    dealerInScope.setCode(code);
                }
                return dealerInScope;
            }
        }
        return null;
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月10日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getCodeValue(java.lang.String)
    **/
    @Override
    public List<CodeInfo> getCodeValue(String partTypeValue) throws AppException {
        return codeMappingDao.getCodeInfoByCodeType(partTypeValue);
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月10日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getCode(java.lang.String)
    **/
    @Override
    public String getCode(String codeValue,String codeType) throws AppException {
        List<CodeInfo> list = codeMappingDao.getCodeInfoByCodeValueAndCodeType(codeValue, codeType);
        if(list != null && !list.isEmpty()){
            return list.get(0).getCode();
        }
        return null;
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月12日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getTypeValueList(java.lang.String)
    **/
    @Override
    public List<String> getTypeValueList(String codeType) throws AppException {
        return codeMappingDao.getTypeValueList(codeType);
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月12日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getPositionGroupList(java.lang.String)
    **/
    @Override
    public List<String> getPositionGroupList(String productType,String productTypeValue) throws AppException {
        return codeMappingDao.getPositionGroupList(productType, productTypeValue);
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月12日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getCodeValueByCodeTypeList(java.util.List)
    **/
    @Override
    public List<String> getCodeValueByCodeTypeList(List<String> codeTypeList) throws AppException {
        List<String> codeValueList =null;
        if(codeTypeList != null && !codeTypeList.isEmpty()){
            StringBuffer buf = new StringBuffer();
            String codeTypes = "";
            for(int i=0; i<codeTypeList.size(); i++){
                if(i == (codeTypeList.size()-1)){
                    buf.append("'" + codeTypeList.get(i) + "'");
                }else{
                    buf.append("'" + codeTypeList.get(i) + "',");
                }
            }
            codeTypes = buf.toString();
            return codeMappingDao.getCodeValueByCodeTypeList(codeTypes, codeTypeList.size()-1);
        }
        return codeValueList;
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月13日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#isExitsRowInEligibility(java.lang.Long)
    **/
    @Override
    public Long isExitsRowInEligibility(Long id) throws AppException {
        Long isExsit=null;
        List<BigInteger> rowList = codeMappingDao.isExitsRowInEligibility(id);
        if (rowList != null && !rowList.isEmpty()) {
            isExsit=rowList.get(0).longValue();
        }else{
            isExsit=null;
        }
        return isExsit;
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月13日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#changeRowInEligibility(java.lang.Long, java.lang.String, java.lang.String, java.lang.String)
    **/
    @Override
    public void changeRowInEligibility(Long ticketLineId, String category, String name,
        String marsIntegrated,Long id) throws AppException {
        try {
            Eligibility eligibility = new Eligibility();
            eligibility.setCategory(category);
            eligibility.setName(name);
            eligibility.setTicketDefLineId(ticketLineId);
            eligibility.setMarsIntegrated(marsIntegrated);
            eligibility.setId(id);
            eligibilityDao.update(eligibility);
        } catch (Exception e) {
            LOGGER.error("changeRowInEligibilityError", e);
        }
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月13日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#saveRowInEligibility(java.lang.Long, java.lang.String, java.lang.String, java.lang.String)
    **/
    @Override
    public void saveRowInEligibility(Long ticketLineId, String category, String name,
        String marsIntegrated) throws AppException {
        try {
            Eligibility eligibility = new Eligibility();
            eligibility.setCategory(category);
            eligibility.setName(name);
            eligibility.setTicketDefLineId(ticketLineId);
            eligibility.setMarsIntegrated(marsIntegrated);
            eligibilityDao.save(eligibility);
        } catch (Exception e) {
            LOGGER.error("saveRowInEligibilityError", e);
        }
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月15日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getEligibilityLineByEligibilityId(java.lang.Long)
    **/
    @Override
    public List<EligibilityLine> getEligibilityLineByEligibilityId(Long id) throws AppException {
        return eligibilityLineDao.getEligibilityLineByEligibilityId(id);
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月15日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getCodeInfoByValueAndType(java.lang.String, java.lang.String)
    **/
    @Override
    public List<CodeInfo> getCodeInfoByValueAndType(String value, String type) throws AppException {
        return codeMappingDao.getCodeInfoByCodeValueAndCodeType(value, type);
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月15日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getCodeByValue(java.lang.String)
    **/
    @Override
    public List<String> getCodeByValue(String value) throws AppException {
        return codeMappingDao.getCodeByValue(value);
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月15日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getParentCodeByValue(java.lang.String)
    **/
    @Override
    public List<String> getParentCodeByValue(String value) throws AppException {
        return codeMappingDao.getParentCodeByValue(value);
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月16日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getParentCodeByCodeType(java.lang.String)
    **/
    @Override
    public String getParentCodeByCodeType(String type) throws AppException {
        List<String> list = codeMappingDao.getParentCodeByCodeType(type);
        if(list != null && !list.isEmpty()){
            return list.get(0);
        }
        return null;
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月17日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#removeRowByEligibilityId(java.lang.Long)
    **/
    @Override
    public void removeRowByEligibilityId(Long eligibilityId) throws AppException {
        eligibilityLineDao.removeRowByEligibilityId(eligibilityId);
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月17日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#removeEligibilityByTicketLineId(java.lang.Long)
    **/
    @Override
    public void removeEligibilityByTicketLineId(Long id) throws AppException {
        eligibilityDao.removeEligibilityByTicketLineId(id);
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月19日
     * @see com.cap.bts.crmdp.dealer.coupon.service.ITicKetDefineService#getTicketPriceOfDealerByDealerIdAndTicketLineIdAndObjType(java.lang.Long, java.lang.Long, java.lang.String)
    **/
    @Override
    public List<TicketPriceOfDealer> getTicketPriceOfDealerByDealerIdAndTicketLineIdAndObjType(
        Long dealerId, Long ticketLineId, String objectType) throws AppException {
        return ticketPriceOfDealerDao.getTicketPriceOfDealerByDealerIdAndTicketLineIdAndObjType(dealerId, ticketLineId, objectType);
    }

}
